<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: edit.phtml 4700 2010-08-16 16:14:34Z jam-gate.vn $
 * @since		2.0.0
 */
?>
<?php 
$this->headTitle($this->translator('customer_edit_page_title'));

$this->headScript()
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/tomato/util.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.slideviewer/jquery.slideviewer.1.2.js');
?>
<link media="all" type="text/css" href="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.ui/themes/base/ui.core.css" rel="stylesheet">				
<link media="all" type="text/css" href="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.ui/themes/base/ui.resizable.css" rel="stylesheet">		
<link media="all" type="text/css" href="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.ui/themes/base/ui.dialog.css" rel="stylesheet">
<link media="all" type="text/css" href="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.ui/themes/base/ui.theme.css" rel="stylesheet">

<script language="JavaScript" type="text/JavaScript" src="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.ui/ui.core.js"></script>		
<script language="JavaScript" type="text/JavaScript" src="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.ui/ui.draggable.js"></script>		
<script language="JavaScript" type="text/JavaScript" src="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.ui/ui.resizable.js"></script>
<script language="JavaScript" type="text/JavaScript" src="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.ui/ui.dialog.js"></script>
<div class="grid_12 t_a_ui_breadcrumb">
	<div class="grid_11 alpha">
		<span><a href="<?php echo $this->url(array(), 'customer_customer_list'); ?>"><?php echo $this->translator('customer_list_breadcrumb'); ?></a></span>
		<span><?php echo $this->translator('customer_edit_breadcrumb'); ?></span>
	</div>	
	<div class="grid_1 omega"><?php echo $this->languageSwitcher('flag', str_repeat('&nbsp;', 2)); ?></div>
</div>

<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>

<form method="post" action="<?php echo $this->url(array(), 'customer_customer_edit'); ?>" id="editCustomerForm">
<div class="grid_12 t_a_bottom"><?php echo $this->translator('customer_edit_guide'); ?></div>

<div class="grid_12 t_a_bottom">
		<div class="grid_9 alpha">
			<div class="grid_9">
				<label><?php echo $this->translator('customer_customer_id'); ?>:</label>
				<input size="8" readonly="readonly" type="text" id="customer_id" name="customer_id" value="<?php echo $this->customer->id;?>" readonly="readonly" class="lock" />
				<input type="hidden" id="shop_id" name="shop_id" value="<?php echo $this->customer->shop_id;?>"/>
			</div>
			<hr/>
			<div class="grid_9">
				<div class="grid_5 alpha">
					<label><?php echo $this->translator('customer_name'); ?>:</label>
					<input maxlength="255" type="text" id="name" name="name" title="<?php echo $this->customer->name;?>" size="30"/>					
				</div>			
				<div class="grid_4 omega">			
					<label style="width:auto;width:100px;"><?php echo $this->translator("core_sex","core");?></label>
					<select name="sex" id="sex">
						<option value="male" <?php if($this->customer->sex=="male") echo 'selected="selected"';?>><?php echo $this->translator("core_sex_male","core");?></option>
						<option value="female" <?php if($this->customer->sex=="female") echo 'selected="selected"';?>><?php echo $this->translator("core_sex_female","core");?></option>
					</select>
				</div>
			</div>
			<hr/>
			<div class="grid_9">
				<div class="grid_5 alpha">			
					<label><?php echo $this->translator("core_birthday","core");?></label>
					<input style="float:left;" type="text" name="birthday" id="birthday" value="<?php echo $this->customer->birthday?>" size="10">
					<script type="text/javascript">
						$(document).ready(function(){
							<?php if($this->customer->birthday && $this->customer->birthday!="0000-00-00"):?>
							$("#birthday").val(Date.parse($("#birthday").val()).toString('dd/MM/yyyy'));
							<?php endif;?>
							$("#birthday").mask("99/99/9999");	
						});
					</script>
				</div>
				<div class="grid_4 omega">			
					<label style="width:auto;width:100px;"><?php echo $this->translator("core_tel","core");?></label>
					<input style="float:left;" type="text" name="tel" id="tel" title="<?php echo $this->customer->tel?>" size="11">
				</div>
			</div>
			<hr/>
			<div class="grid_9">
				<div class="grid_5 alpha">			
					<label><?php echo $this->translator("core_address","core");?></label>
					<input style="float:left;" type="text" name="address" id="address" title="<?php echo $this->customer->address?>" size="30">
				</div>
				<div class="grid_4 omega">			
					<label style="width:auto;width:100px;"><?php echo $this->translator("core_email","core");?></label>
					<input style="float:left;" type="text" name="email" id="email" title="<?php echo $this->customer->email?>">
				</div>
			</div>
			<hr/>
			<div class="grid_9">
					<label><?php echo $this->translator("customer_customer_first_time");?></label>
					<input style="float:left;" type="text" name="first_time" id="first_time" value="<?php echo $this->customer->first_time?>" size="10">
					<label style="width:auto;margin-left:8px;"><?php echo $this->translator("customer_customer_last_time");?></label>
					<input style="float:left;" type="text" name="last_time" id="last_time" value="<?php echo $this->customer->last_time?>" size="10">
					<label style="width:auto;margin-left:8px;"><?php echo $this->translator("customer_customer_amount_time");?></label>
					<input style="float:left;" type="text" name="amount_time" id="amount_time" value="<?php echo $this->customer->amount_time?>" size="3">
					<script type="text/javascript">
						$(document).ready(function(){
							<?php if($this->customer->first_time && $this->customer->first_time!="0000-00-00"):?>
							$("#first_time").val(Date.parse($("#first_time").val()).toString('dd/MM/yyyy'));
							<?php endif;?>
							$("#first_time").mask("99/99/9999");
							<?php if($this->customer->last_time && $this->customer->last_time!="0000-00-00"):?>	
							$("#last_time").val(Date.parse($("#last_time").val()).toString('dd/MM/yyyy'));
							<?php endif;?>
							$("#last_time").mask("99/99/9999");	
						});
					</script>
			</div>
			<hr/>
			<div class="grid_9">			
				<label><?php echo $this->translator("customer_customer_first_deposit");?></label>
				<input style="float:left;" type="text" name="first_deposit" id="first_deposit" value="<?php echo $this->customer->first_deposit?>" class="lock" readonly="readonly">
				<label style="float:left;width:auto;margin-left:5px;"><?php echo $this->customer->currency;?></label>
				
			</div>
			<hr/>
			<div class="grid_9">			
				<label><?php echo $this->translator("customer_customer_remaining_money");?></label>
				<input style="float:left;" type="text" name="remaining_money" id="remaining_money" value="<?php echo $this->customer->remaining_money?>" class="lock" readonly="readonly">
				<label style="float:left;width:auto;margin-left:5px;"><?php echo $this->customer->currency;?></label>
			</div>
			<hr/>
			<div class="grid_9">			
				<label><?php echo $this->translator("customer_customer_employee_id");?></label>
				<?php
					echo $this->helperLoader('employee')->listEmployee("employee_id",$this->customer->employee_id); 
				?>
			</div>
			<hr/>
			<div class="grid_9">			
				<label><?php echo $this->translator("customer_customer_referrer_id");?></label>
				<?php
					echo $this->helperLoader('employee')->listEmployee("referrer_id",$this->customer->referrer_id,true); 
				?>
			</div>
			<hr/>
			<div class="grid_9">			
				<label><?php echo $this->translator("customer_customer_note");?></label>
				<textarea rows="3" cols="63" name="note" id="note"><?php echo $this->customer->note?></textarea>
			</div>
			<hr/>
			<div class="grid_9">
				<button style="float:right;margin-right:20px;"><span><?php echo $this->translator("customer_add_save_button");?></span></button>
			</div>
		</div>
		<div class="grid_3 omega">
			<?php
				echo $this->helperLoader('core')->listImage("images",$this->customer->images,"customer",$this->customer->id); 
			?>		    			
		</div>
</form>

<script type="text/javascript">
$(document).ready(function() {
	$('#editCustomerForm').validate({
		rules: {
			name: {
				required: true,
		  		maxlength: 255
			},
			sex: {
				required: true
			},
			birthday: {
				required:true,
				date: true
			},
			email: {
				required:true,
				email: true
			},
			first_time:{
				date: true
			},
			last_time:{
				date: true
			},
			amount_time:{
				digits: true
			}
	    },
	    messages: {
	    	name: {
				required: "<?php echo $this->translator("custommer_message_name_required");?>",
		  		maxlength: "<?php echo $this->translator("custommer_message_name_max_length");?>"
			},
			sex: {
				required: "<?php echo $this->translator("custommer_message_sex_required");?>"
			},
			birthday: {
				required: "<?php echo $this->translator("custommer_message_birthday_required");?>",
				date: "<?php echo $this->translator("custommer_message_date_format");?>"
			},
			email: {
				required:"<?php echo $this->translator("custommer_message_email_required");?>",
				email: "<?php echo $this->translator("custommer_message_email_format");?>"
			},
			first_time:{
				date: "<?php echo $this->translator("custommer_message_date_format");?>"
			},
			last_time:{
				date: "<?php echo $this->translator("custommer_message_date_format");?>"
			},
			amount_time:{
				digits: "<?php echo $this->translator("custommer_message_numeric_format");?>"
			}	    	
		}
	});
});
</script>